import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
// 爱试用
const Index = () => import('../page/index')
const Login = () => import('../page/login')
const Active = () => import('../page/active')
const ExchangeGold = () => import('../page/exchange-gold')
const ExchangeSliver = () => import('../page/exchange-sliver')
const ExchangeEnd = () => import('../page/exchange-end')
const Levis = () => import('../page/levis')

const router = new Router({
  routes: [
    // 登录
    {
      path: '/login',
      name: 'login',
      component: Login,
      meta: {
        title: '登录'
      }
    },
    // 首页
    {
      path: '/index',
      name: 'index',
      component: Index,
      meta: {
        title: '首页'
      }
    },
    // 活动须知
    {
      path: '/active',
      name: 'active',
      component: Active,
      meta: {
        title: '活动说明'
      }
    },
    // 积分兑换
    {
      path: '/exchange-gold',
      name: 'exchange-gold',
      component: ExchangeGold,
      meta: {
        title: '积分兑换'
      }
    },
    {
      path: '/exchange-sliver',
      name: 'exchange-sliver',
      component: ExchangeSliver,
      meta: {
        title: '积分兑换'
      }
    },
    // 兑换结束
    {
      path: '/exchange-end',
      name: 'exchange-end',
      component: ExchangeEnd,
      meta: {
        title: '兑换结束'
      }
    },
    // 福袋
    {
      path: '/levis',
      name: 'levis',
      component: Levis,
      meta: {
        title: '福袋'
      }
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.meta.title) { // 如果设置标题，拦截后设置标题
    document.title = to.meta.title
  }
  next()
})
export default router
